package com.intellagric.controller.module.ift_warning_config;

import com.alibaba.dubbo.config.support.Parameter;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.IftWarningConfig;
import com.intellagric.service.iftmonitor.ift_warning_config.WarningConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/25
 * @DESC： 预警阈值配置信息管理
 */
@Controller
public class WarningConfigController {

    @Autowired
    private WarningConfigService warningConfigService;

    /**
     * 添加预警阈值配置信息
     * @Param warningConfig
     * @return ResponseMessage
     */
    @RequestMapping("/warning/config/add")
    @ResponseBody
    public ResponseMessage add(IftWarningConfig warningConfig) {
        //初始化参数
        warningConfig.setId(UUID.randomUUID().toString().replaceAll("-",""));
        warningConfig.setCreateDate(new Date());
        warningConfig.setUpdateDate(new Date());
        return warningConfigService.addWarningConfig(warningConfig);
    }

    /**
     * 删除预警阈值配置信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/warning/config/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return warningConfigService.deleteWarningConfig(id);
    }

    /**
     * 修改预警阈值配置信息
     * @Param warningConfig
     * @return ResponseMessage
     */
    @RequestMapping("/warning/config/edit")
    @ResponseBody
    public ResponseMessage edit(IftWarningConfig warningConfig) {
        warningConfig.setUpdateDate(new Date());
        warningConfig.setCreateDate(null);
        return warningConfigService.editWarningConfig(warningConfig);
    }

    /**
     * 查询预警阈值配置信息
     * @return IftWarningConfig
     */
    @RequestMapping("/warning/config/{id}")
    @ResponseBody
    public IftWarningConfig get(@PathVariable String id) {
        return warningConfigService.getWarningConfigById(id);
    }

    /**
     * 查询预警阈值配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/warning/config/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return warningConfigService.getWarningConfigList();
    }

    /**
     * 通过场景查询预警阈值配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/warning/config/list/{sceneId}")
    @ResponseBody
    public LayuiDataGridResult getList(@PathVariable String sceneId) {
        return warningConfigService.getWarningConfigListByScenery(sceneId);
    }

    /**
     * 通过场景和检查项查询预警阈值配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/warning/config/equipment/list")
    @ResponseBody
    public LayuiDataGridResult getListById(String sceneId,String checkItemId) {
        return warningConfigService.getWarningConfigListBySceneryAndChannel(sceneId,checkItemId);
    }

    /**
     * 分页查询预警阈值配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/warning/config/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return warningConfigService.getWarningConfigPage(page,limit);
    }

}
